//创建一个pinia仓库
//引入创建仓库函数
import { defineStore } from "pinia";
//引入封装好的接口
import { getCategory1, getCategory2, getCategory3 } from "@/api/produck/attr";
//引入数据类型
import type { resDataList } from "@/api/produck/attr/type";
import type { CategoryData } from "./types/type";
//创建仓库
const useCategoryStore = defineStore("CategoryStore", {
  state: (): CategoryData => {
    return {
      C1Arr: [],
      c1Id: "",
      C2Arr: [],
      c2Id: "",
      C3Arr: [],
      c3Id: "",
    };
  },
  actions: {
    async getC1() {
      let result: resDataList = await getCategory1();
      if (result.code == 200) {
        this.C1Arr = result.data;
      }
    },
    async getC2() {
      let result: resDataList = await getCategory2(this.c1Id);
      if (result.code == 200) {
        this.C2Arr = result.data;
        return "ok";
      }
    },
    async getC3() {
      let result: resDataList = await getCategory3(this.c2Id);
      if (result.code == 200) {
        this.C3Arr = result.data;
      }
    },
  },
  getters: {},
});

export default useCategoryStore;
